<?php
/**
 * @purpose: 对“通知”类型中子类型为11(@user)的编码与解码文件
 * @author: Mandel Woo <wuzhijian@snda.com>

 * @memo: 参阅母板文件
 */
require_once(dirname(__FILE__)."/../../../models/user/UCModUserInfo.php");


function msg_notice_type11_encoder() {
	$num_args = func_num_args();

	if ($num_args == 3) {
		$fields = array("sender_id", "twitter_id","twitter");

	} else if ($num_args == 6) {
		$fields = array("sender_id", "twitter_id","twitter","ori_author","ori_twitter","ori_twitter_id");

	} else {
		return false;
	}


	foreach($fields as $k => $v) {
		eval("\${$v}=func_get_arg($k);");
	}


	return serialize(array(
			"sender_id"      => $sender_id,
			"twitter_id"     => $twitter_id,
			"twitter"        => utf_substr($twitter, 100),
			"ori_author"     => $ori_author,
			"ori_twitter"    => utf_substr($ori_twitter, 100),
			"ori_twitter_id" => $ori_twitter_id,
			));
}

function msg_notice_type11_decoder() {
	$fields = array("id","receiverid","content","createTime","changeFlag","fmt");

	foreach($fields as $k => $v) {
		eval("\${$v}=func_get_arg($k);");
	}


	$data           = unserialize($content);
	$sender_id      = $data['sender_id'];
	$twitter_id     = $data['twitter_id'];
	$twitter        = codeToSmile(nl2br(htmlspecialchars($data['twitter'])));
	$ori_author     = $data['ori_author'];
	$ori_twitter    = codeToSmile(nl2br(htmlspecialchars($data['ori_twitter'])));
	$ori_twitter_id = $data['ori_twitter_id'];


	$users_infos = UCModUserInfo::getUserInfos(array($sender_id,$ori_author), array(USERINFO_NICKNAME));

	$sender_nick = htmlspecialchars($users_infos[$sender_id][USERINFO_NICKNAME]);
	$sender_nick == '' && $sender_nick = $sender_id;
	$sender = "<a href=\"".get_user_home_url($sender_id)."\" target='_blank'>{$sender_nick}</a>";

	$ori_author_nick = htmlspecialchars($users_infos[$ori_author][USERINFO_NICKNAME]);
	$ori_author_nick == '' && $ori_author_nick = $ori_author;
	$ori = "<a href=\"".get_user_home_url($ori_author)."\" target='_blank'>{$ori_author_nick}</a>";


	if ($fmt == 'line') {
		return sprintf("%s的推它@了你", $sender);

	} else if ($fmt == 'box') {
		$cur_user_nick = Yii::app()->user->nick;

		$twitter_html = sprintf("<a href=\"%s\" target=\"_blank\">%s</a>",
			Yii::app()->createUrl("tuita/viewdetail",array('mood_id'=>$twitter_id,'user_id'=>$sender_id)),
			$twitter
			);

		$html = "{$sender}：@{$cur_user_nick}，{$twitter_html}";

		if (!empty($ori_author)) {
			$ori_twitter_html = sprintf("<a href=\"%s\" target=\"_blank\">%s</a>",
				Yii::app()->createUrl("tuita/viewdetail",array('mood_id'=>$ori_twitter_id,'user_id'=>$ori_author)),
				$ori_twitter
				);

			$html .= "<div style=\"background-color:#cde2ed;padding:5px 0 5px 6px;margin-top:10px;margin-left:35px\">@{$ori}：{$ori_twitter_html}</div>";
		}


		return '<div class="font14">' . $html . '</div>';

	} else {
		return '';
	}
}

